﻿using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace ToExcel
{
    internal class SysFast
    {
        internal static string PickFile(string filter)
        {
            using (var dialog = new OpenFileDialog()
            {
                Filter = filter,
                Multiselect = false,
            })
            {
                if (dialog.ShowDialog() == DialogResult.OK &&
                    System.IO.File.Exists(dialog.FileName))
                {
                    return dialog.FileName;
                }
            }
            return string.Empty;
        }
        internal static void OpenFile(string path)
        {
            if (System.IO.File.Exists(path))
            {
                ShellExecute(IntPtr.Zero, "open", path, "", "", ShowCommands.SW_SHOWNORMAL);
            }
        }

        internal enum ShowCommands : int
        {
            SW_HIDE = 0,
            SW_SHOWNORMAL = 1,
            SW_NORMAL = 1,
            SW_SHOWMINIMIZED = 2,
            SW_SHOWMAXIMIZED = 3,
            SW_MAXIMIZE = 3,
            SW_SHOWNOACTIVATE = 4,
            SW_SHOW = 5,
            SW_MINIMIZE = 6,
            SW_SHOWMINNOACTIVE = 7,
            SW_SHOWNA = 8,
            SW_RESTORE = 9,
            SW_SHOWDEFAULT = 10,
            SW_FORCEMINIMIZE = 11,
            SW_MAX = 11
        }
        [DllImport("shell32.dll")]
        internal static extern IntPtr ShellExecute(
            IntPtr hwnd,
            string lpOperation,
            string lpFile,
            string lpParameters,
            string lpDirectory,
            ShowCommands nShowCmd);
    }
}
